package com.example.jdbcdemo.service.Impl;

import com.example.jdbcdemo.mapper.CollectMoneyOrderMapper;
import com.example.jdbcdemo.mapper.CustomerMapper;
import com.example.jdbcdemo.pojo.CollectMoneyOrder;
import com.example.jdbcdemo.pojo.Customer;
import com.example.jdbcdemo.service.CollectMoneyServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class CollectMoneyServiceImpl implements CollectMoneyServiceInterface {

    @Autowired
    CollectMoneyOrderMapper collectMoneyOrderMapper;
    @Autowired
    CustomerMapper customerMapper;

    @Override
    public List<Map<String, Object>> queryCollectOrderList() {
        List<CollectMoneyOrder> orderList=collectMoneyOrderMapper.queryCollectMoneyOrderList();
        List<Map<String, Object>> resultList=new LinkedList<>();
        for (CollectMoneyOrder collectMoneyOrder:orderList)
        {
            Map<String,Object> map=new LinkedHashMap<>();
            Customer customer=customerMapper.queryCustomerById(collectMoneyOrder.getCustomerId());
            map.put("groupId",collectMoneyOrder.getGroupId());
            //客户名称
            map.put("customerName",customer.getName());
            map.put("customerAddress",customer.getAddress());
            map.put("customerTel",customer.getTelphone());
            int type=customer.getCustomerType();
            String types="";
            switch (type){
                case 0:
                    types="零售";
                    break;
                case 1:
                    types="批发";
                    break;
                default:
                    break;
            }
            map.put("customerType",types);//0零售1批发
            map.put("totalPrice",collectMoneyOrder.getTotalPrice());
            map.put("acceptPrice",collectMoneyOrder.getAcceptPrice());
            int status=collectMoneyOrder.getStatus();
            String statuss="";
            switch (status){
                case 0:
                    statuss="未结清";
                    break;
                case 1:
                    statuss="已结清";
                    break;
                default:
                    break;
            }
            map.put("status",statuss);//0未结清1已结清
            map.put("statusCode",status);
            resultList.add(map);
        }
        return resultList;
    }
}
